package inherit;
class Animal{
    public String name;
    public int age;
    static{
        System.out.println("Animal::static{}");
    }
    {
        System.out.println("Animal::{}");
    }

    public Animal(){
        System.out.println("Animal()");
    }
    public Animal(String name,int age) {
        this.name = name;
        this.age = age;
        System.out.println("Animal(String,int)");
    }

    public void eat(){
        System.out.println(name + "吃饭");
    }
}

class Dog extends Animal{
    static {
        System.out.println("Dog::static{}");
    }
    {
        System.out.println("Dog::{}");
    }
    public boolean silly;
    public Dog(){
        System.out.println("Dog()");
    }
    public Dog(String name,int age,boolean silly){
        //1,先帮助父类部分初始化
        super(name,age);//必须放到第一行，先初始化父类部分
        this.silly=silly;
        System.out.println("Dog(String name,int age,boolean silly)");
    }

    public String name = "hello";
    public void houseGuard(){
        System.out.println(super.name + "正在看家护院");//super关键字，访问父类中和子类同名的变量,只能在非静态方法使用
        /*
        1,this会优先访问子类自己的，如果子类没有就访问父类的
        2，super只是一个关键字，在代码层面上能达到易读的效果
         */
    }
}

class Cat extends Animal{
    static {
        System.out.println("Cat::static{}");
    }
    {
        System.out.println("Cat::{}");
    }

    public Cat(){
        super("咪咪",10);
        System.out.println("Cat()");
    }

    public Cat(String name,int age){
        super(name,age);
        System.out.println("Cat(String name,int age)");
    }
}

public class Test2 {
    public static void main(String[] args) {
        Dog dog = new Dog("旺财",8,true);//先执行static代码块
        System.out.println("===============");
        Dog dog2 = new Dog("hello",10,false);
        //Cat cat = new Cat();
    }
}
